<div id="userManager">
<div id="tabs-1">
<form method="post" action="#">
	<fieldset>
		<legend>Search</legend>
			<p>
				<label for="mf">Medium Field: </label>
 				<input class="Username" name="inputUsername" type="text" value="" /> <span class="validate_success">A positive message!</span>
			</p>
			<p>
				<label for="dropdown">List Name: </label>
				<select name="dropdown" class="dropdown">
					<option>Please select an option</option>
					<?php foreach ($arrUser as $userInfo){?>
						<option><?php echo  $userInfo['Users']['username']?></option>
					<?php }?>
				</select>
			</p>
			<p>
				<input  class="button" type="button" value="Search" />
			</p>
	</fieldset>
</form>
</div>
<span>Number record : <?php echo $usernumber;?></span>
<div id="tabs-2">
	<table class="fullwidth" cellpadding="0" cellspacing="0" border="0">
		<thead>
			<tr>
				<td>ID.</td>
				<td>Avata</td>
				<td>Name</td>
				<td>E-Mail</td>
				<td>Birthdate</td>
				<td>TotalMoney</td>
				<td>Create Time</td>
				<td>Grounp Id</td>
				<td>Delete</td>
			</tr>
		</thead>
		<?php
			if($dataview){
		 		foreach ($dataview as $view){
					echo $view;
				}
			}else{
			
		?>
		<span class="validate_success">A positive message!</span>
	<?php }?>
	</table>
</div>
</div>

<thead>
</thead>
<div id ="viewInfo"  style="display:none">
	<fieldset>
	<legend>User Info</legend>
		<div class = "info" style="float: left;">
			
			<p>
				<label for="sf">Username</label>
				<input class="sf" name="username" disabled="disabled" type="text" value="" />
			</p>
			<p>
				<label for="mf">Email: </label>
	 			<input class="mf" name="Email" disabled="disabled" type="text" value="" /> 
			</p>
			<p>
				<label for="mf">Brithday: </label>
	 			<input class="mf" name="brithday" disabled="disabled" type="text" value="" /> 
			</p>
			<p>
				<label for="mf">Total Money: </label>
	 			<input class="mf" name="brithday" disabled="disabled" type="text" value="" /> 
			</p>
			<p>
				<label for="dropdown">DropDown: </label>
				<select name="dropdown" class="grounpId">
					<option>Please select an option</option>
					<option value = '0'>Admin</option>
					<option value = '1'>User</option>
				</select>
		</p>
		</div>
		<div id = "avata" style ="float: right;">
			<p>
	 			<img alt="avata" width="200px" height="200px" src="">
			</p>
			
		</div>
	</fieldset>

	<input class="button reset" type="button" value="Reset">
	<input class="update" type="button" value="Reset">
</div>

<script type="text/javascript">
	$(document).ready(function(){
		$('.username').click(function(){
			var username = $(this).text();
			alert(username); 
			$.ajax({ 
				 type: 'POST',
				 url:  '/Users/info',
				 data: {'username' : username },
				 dataType:'json', 
				 success: function(data){
					/// console.log(data); return false;
					// $("span.company_name").html(data.publisherInfo.Publisher.company_name);
					console.log(data.Users.username);
					var grounp ;
					if(data.Users.group_id == 0){
						grounp = 'Admin';
					}else{
						grounp = 'User';
					}
					$('input[name="username"]').attr('value',data.Users.username);
					$('input[name="Email"]').attr('value',data.Users.email);
					$('input[name="brithday"]').attr('value',data.Users.brithday);
					$('input[name="Email"]').attr('value',data.Users.email);
					$('input[name="grounpId"]').attr('value',grounp);
					$('#avata img').attr('src',data.Users.avata);
					$("#userManager").slideUp();
					$("#viewInfo").slideDown();
				 }
				 }); 
			
		});
		$('.reset').click(function(){
			$("#userManager").slideDown();
			$("#viewInfo").slideUp();
		});
		$('.update').click(function(){
			var grounpId = $('.grounpId').val();
			var username = $('input[name="username"]').val();
			var Email	 = $('input[name="Email"]').val();
			var brithday = $('input[name="brithday"]').val();
			if(grounpId == '0' || grounpId =='1'){
				$.ajax({ 
					 type: 'POST',
					 url:  '/Users/update',
					 data: {'username' : username ,'grounpId':grounpId,'Email':Email,'brithday':brithday},
					 dataType:'json', 
					 success: function(data){
						
						alert('ok'); return false;
					 }
					 });
		}else{
			alert('Bạn chưa phân quyên cho user '+username); return false;
		}
		});
		$('.button').click(function(){
			var Username =  $('input[name="inputUsername"]').val();
			window.location.href ='?user='+Username;
		});
		$('.deleteUser').click(function(){
			var Username =  $(this).attr("uid");
			window.location.href ='?uid='+Username;
		});

	});
	
</script>